#include "al.h" 
#include "jni.h"
#include<stdio.h>
#include<android/log.h>
#include "common.h"
#ifndef _TYPETRANS_
#define _TYPETRANS_

#define CYCLE_OUTPUT_LEN 17

#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE,"jni" ,__VA_ARGS__) // 定义LOGF类型
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,"jni" ,__VA_ARGS__) // 定义LOGW类型
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,"jni" ,__VA_ARGS__) // 定义LOGI类型
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,"jni" ,__VA_ARGS__) // 定义LOGW类型
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,"jni" ,__VA_ARGS__) // 定义LOGE类型


dayUnitDSInput* jObjectTransDayInput(JNIEnv *env,jobjectArray dayInputArray,int length){
	if(dayInputArray == 0 || length == 0){
		return NULL;
	}
	dayUnitDSInput* dayInputReturn = createDayInputNum(length);
	if(!dayInputReturn) return NULL; 
	jobject dayInputx = (jobject)(*env)->GetObjectArrayElement(env,dayInputArray,0);
	jclass dayInputclass =  (*env)->GetObjectClass(env,dayInputx);
	jfieldID dayOfCycleID = (*env)->GetFieldID(env,dayInputclass,"dayOfCycle","I");
	jfieldID dateID       = (*env)->GetFieldID(env,dayInputclass,"date","J");
	jfieldID BBTID 		  =	(*env)->GetFieldID(env,dayInputclass,"BBT","F");
	
	jfieldID menstruationRecordID = (*env)->GetFieldID(env,dayInputclass,"menstruationRecord","I");
	jfieldID cervicalMunusRecordID = (*env)->GetFieldID(env,dayInputclass,"cervicalMunusRecord","I");
	jfieldID ovulationTestResultID = (*env)->GetFieldID(env,dayInputclass,"ovulationTestResult","I");
	jfieldID tempFlagID = (*env)->GetFieldID(env,dayInputclass,"tempFlag","I");
	int x = 0;
	for(x = 0; x < length; x++){
		jobject dayInput = (jobject)(*env)->GetObjectArrayElement(env,dayInputArray,x);

		jint dayOfCycleValue  = (*env)->GetIntField(env,dayInput,dayOfCycleID);
		jlong dateValue       = (*env)->GetLongField(env,dayInput,dateID);
		jfloat BBT  		  = (*env)->GetFloatField(env,dayInput,BBTID);
		//printf("BBT_--->%f",BBT);
		jint menstruationRecord  = (*env)->GetIntField(env,dayInput,menstruationRecordID);
		jint cervicalMunusRecord  = (*env)->GetIntField(env,dayInput,cervicalMunusRecordID);
		jint ovulationTestResult  = (*env)->GetIntField(env,dayInput,ovulationTestResultID);
		jint tempFlag  = (*env)->GetIntField(env,dayInput,tempFlagID);
		dayInputReturn[x].dayOfCycle = dayOfCycleValue;
		dayInputReturn[x].date =  dateValue;
		dayInputReturn[x].BBT = BBT;
		dayInputReturn[x].menstruationRecord = menstruationRecord;
		dayInputReturn[x].cervicalMunusRecord = cervicalMunusRecord;
		dayInputReturn[x].ovulationTestResult = ovulationTestResult;
		dayInputReturn[x].tempFlag = tempFlag;
	//	printf("day in cycle:%d   ",dayOfCycleValue);
	//	printf("date : %d\n",dateValue); 
	//	fflush(stdout);
	}
	return dayInputReturn;
}

void testTransDayInput(dayUnitDSInput* dayInput, int length){
	int x = 0;
	for(;x< length;x++){
		printf("\n DayUnitDSInput show->\n");
		printf("dayOfCycle:%d",dayInput[x].dayOfCycle);
		printf("    date:%ld",dayInput[x].date);
		printf("    BBT:%.2f",dayInput[x].BBT);
		printf("    menstruationRecord:%d",dayInput[x].menstruationRecord);
		printf("    cervicalMunusRecord:%d",dayInput[x].cervicalMunusRecord);
		printf("    ovulationTestResult:%d",dayInput[x].ovulationTestResult);
		printf("    tempFlag:%d",dayInput[x].tempFlag);	
	}
}
/*//此函数被注释的原因是在android端运行的时候，对于长整形数组的操作可能会出现问题，所以进行注释 ，如果运行的系统是window或者是linux就不会出现问题，
cycleUnitDS* jObjectTransCycleInput(JNIEnv *env,jobjectArray cycleInputArray, int cycleInputLength){
	if(cycleInputArray == 0 || cycleInputLength == 0){
		return NULL;
	}
	cycleUnitDS * cycleReturn = createCycleUnitNum(cycleInputLength);
	if(!cycleReturn) return NULL;
	
	jobject cycleInputx = (jobject)(*env)->GetObjectArrayElement(env,cycleInputArray,0);
	jclass cycleClass   = (*env)->GetObjectClass(env,cycleInputx);
	jfieldID cycleDataID = (*env)->GetFieldID(env,cycleClass,"cycleData","[J");
  	jfieldID cycleNumberID = (*env)->GetFieldID(env,cycleClass,"cycleNumber","I");
  	jfieldID ovulationDayUserRecordBasisID = (*env)->GetFieldID(env,cycleClass,"ovulationDayUserRecordBasis","I");
  	int x = 0;
  	for(x = 0; x < cycleInputLength; x++){
		jobject cycleInput = (jobject)(*env)->GetObjectArrayElement(env,cycleInputArray,x);

		jint cycleNumberValue  = (jint)(*env)->GetIntField(env,cycleInput,cycleNumberID);
		jint ovulationDayUserRecordBasis = (jint)(*env)->GetIntField(env,cycleInput,ovulationDayUserRecordBasisID);
		
		jlongArray cycleDataArray = (jlongArray)(*env)->GetObjectField(env,cycleInput,cycleDataID);
		LOGW("cycleNum:%d\n",cycleNumberValue);
		jsize cycleDataLength = (jsize)(*env)->GetArrayLength(env,cycleDataArray);
		
		jlong *cycleData = (*env)->GetLongArrayElements(env,cycleDataArray,0);
		int index = 0;
		for( index = 0 ; index < cycleDataLength; index++){
			LOGW("cycleData %d --> %d\n",index,cycleData[index]);
			cycleReturn[x].cycleData[index] = cycleData[index];
		}
		cycleReturn[x].cycleNumber = cycleNumberValue;
		cycleReturn[x].ovulationDayUserRecordBasis = ovulationDayUserRecordBasis;
	}
	return cycleReturn;
}
*/

cycleUnitDS* jObjectTransCycleInput(JNIEnv *env,jobjectArray cycleInputArray, int cycleInputLength){
	if(cycleInputArray == 0 || cycleInputLength == 0){
		return NULL;
	}
	cycleUnitDS * cycleReturn = createCycleUnitNum(cycleInputLength);
	if(!cycleReturn) return NULL;
	
	jobject cycleInputx = (jobject)(*env)->GetObjectArrayElement(env,cycleInputArray,0);
	jclass cycleClass   = (*env)->GetObjectClass(env,cycleInputx);
	
  	jfieldID cycleNumberID = (*env)->GetFieldID(env,cycleClass,"cycleNumber","I");
  	jfieldID ovulationDayUserRecordBasisID = (*env)->GetFieldID(env,cycleClass,"ovulationDayUserRecordBasis","I");
  	
	jfieldID cycleDataID_0 = (*env)->GetFieldID(env,cycleClass,"menstruationStartForecast","J");
	jfieldID cycleDataID_1 = (*env)->GetFieldID(env,cycleClass,"menstruationEndForecast","J");
	jfieldID cycleDataID_2 = (*env)->GetFieldID(env,cycleClass,"menstruationStartConfirm","J");
	jfieldID cycleDataID_3 = (*env)->GetFieldID(env,cycleClass,"menstruationEndConfirm","J");
	jfieldID cycleDataID_4 = (*env)->GetFieldID(env,cycleClass,"BBTRiseDay","J");
	jfieldID cycleDataID_5 = (*env)->GetFieldID(env,cycleClass,"peakDay","J");
	jfieldID cycleDataID_6 = (*env)->GetFieldID(env,cycleClass,"ovulationDayForecast","J");
	jfieldID cycleDataID_7 = (*env)->GetFieldID(env,cycleClass,"ovulationDayConfirm","J");
	jfieldID cycleDataID_8 = (*env)->GetFieldID(env,cycleClass,"ovulationDayUserRecord","J");
	jfieldID cycleDataID_9 = (*env)->GetFieldID(env,cycleClass,"ovulationDayBBTRise","J");
	jfieldID cycleDataID_10 = (*env)->GetFieldID(env,cycleClass,"ovulationDayNextMenstruation","J");
	jfieldID cycleDataID_11 = (*env)->GetFieldID(env,cycleClass,"fertileWindowStartForecast","J");
	jfieldID cycleDataID_12 = (*env)->GetFieldID(env,cycleClass,"fertileWindowEndForecast","J");
	jfieldID cycleDataID_13 = (*env)->GetFieldID(env,cycleClass,"fertileWindowStartConfirm","J");
	jfieldID cycleDataID_14 = (*env)->GetFieldID(env,cycleClass,"fertileWindowEndConfirm","J");
	jfieldID cycleDataID_15 = (*env)->GetFieldID(env,cycleClass,"dangerWindowStartForecast","J");
	jfieldID cycleDataID_16 = (*env)->GetFieldID(env,cycleClass,"dangerWindowEndForecast","J");
	jfieldID cycleDataID_17 = (*env)->GetFieldID(env,cycleClass,"dangerWindowStartConfirm","J");
	jfieldID cycleDataID_18 = (*env)->GetFieldID(env,cycleClass,"dangerWindowEndConfirm","J");
	jfieldID cycleDataID_19 = (*env)->GetFieldID(env,cycleClass,"nextMenstruationStartForecast","J");
	jfieldID cycleDataID_20 = (*env)->GetFieldID(env,cycleClass,"nextMenstruationEndForecast","J");
	jfieldID cycleDataID_21 = (*env)->GetFieldID(env,cycleClass,"nextOvulationDayForecast","J");
	jfieldID cycleDataID_22 = (*env)->GetFieldID(env,cycleClass,"nextFertileWindowStartForecast","J");
	jfieldID cycleDataID_23 = (*env)->GetFieldID(env,cycleClass,"nextFertileWindowEndForecast","J");
	jfieldID cycleDataID_24 = (*env)->GetFieldID(env,cycleClass,"nextDangerWindowStartForecast","J");
	jfieldID cycleDataID_25 = (*env)->GetFieldID(env,cycleClass,"nextDangerWindowEndForecast","J");
	
	
	
	
	int x = 0;
  	for(x = 0; x < cycleInputLength; x++){
		LOGW("Log in C al jObjectTransCycleInput index:%d\n",x);
		jobject cycleInput = (jobject)(*env)->GetObjectArrayElement(env,cycleInputArray,x);

		jint cycleNumberValue  = (jint)(*env)->GetIntField(env,cycleInput,cycleNumberID);
		jint ovulationDayUserRecordBasis = (jint)(*env)->GetIntField(env,cycleInput,ovulationDayUserRecordBasisID);
		
		jlong cyData0 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_0);
		jlong cyData1 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_1);
		jlong cyData2 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_2);
		jlong cyData3 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_3);
		jlong cyData4 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_4);
		jlong cyData5 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_5);
	
		jlong cyData6 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_6);
		jlong cyData7 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_7);
		jlong cyData8 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_8);
		jlong cyData9 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_9);
		jlong cyData10 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_10);
		jlong cyData11 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_11);
		
		jlong cyData12 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_12);
		jlong cyData13 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_13);
		jlong cyData14 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_14);
		jlong cyData15 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_15);
		jlong cyData16 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_16);
		jlong cyData17 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_17);
		
		jlong cyData18 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_18);
		jlong cyData19 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_19);
		jlong cyData20 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_20);
		jlong cyData21 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_21);
		jlong cyData22 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_22);
		jlong cyData23 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_23);
		
		jlong cyData24 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_24);
		jlong cyData25 =  (jlong)(*env)->GetLongField(env,cycleInput,cycleDataID_25);
				
		cycleReturn[x].cycleNumber = cycleNumberValue;
		cycleReturn[x].ovulationDayUserRecordBasis = ovulationDayUserRecordBasis;
		cycleReturn[x].cycleData[0] = cyData0;
		cycleReturn[x].cycleData[1] = cyData1;
		cycleReturn[x].cycleData[2] = cyData2;
		cycleReturn[x].cycleData[3] = cyData3;
		cycleReturn[x].cycleData[4] = cyData4;
		cycleReturn[x].cycleData[5] = cyData5;
		cycleReturn[x].cycleData[6] = cyData6;
		cycleReturn[x].cycleData[7] = cyData7;
		cycleReturn[x].cycleData[8] = cyData8;
		cycleReturn[x].cycleData[9] = cyData9;
		cycleReturn[x].cycleData[10] = cyData10;
		cycleReturn[x].cycleData[11] = cyData11;
		cycleReturn[x].cycleData[12] = cyData12;
		cycleReturn[x].cycleData[13] = cyData13;
		cycleReturn[x].cycleData[14] = cyData14;
		cycleReturn[x].cycleData[15] = cyData15;
		cycleReturn[x].cycleData[16] = cyData16;
		cycleReturn[x].cycleData[17] = cyData17;
		cycleReturn[x].cycleData[18] = cyData18;
		cycleReturn[x].cycleData[19] = cyData19;
		cycleReturn[x].cycleData[20] = cyData20;
		cycleReturn[x].cycleData[21] = cyData21;
		cycleReturn[x].cycleData[22] = cyData22;
		cycleReturn[x].cycleData[23] = cyData23;
		cycleReturn[x].cycleData[24] = cyData24;
		cycleReturn[x].cycleData[25] = cyData25;
	}
	return cycleReturn;
}








void testTransCycleInput(cycleUnitDS * cycle, int length){
	printf("CycleUnitDS show->");
	int y = 0;
	for(y = 0; y < length; y++){
		printf("\n cycleNumber:%d \n",cycle[y].cycleNumber);
		printf("ovulationDayUserRecordBasis:%d\n",cycle[y].ovulationDayUserRecordBasis);
		printf("cycleData:\n");
		int x = 0;
		for(x = 0; x < 26; x++){
			printf("%ld    ",cycle[y].cycleData[x]);
			if( (x+1)%3 == 0){
				printf("\n");
			}
		}
		printf("\n");	
	}
	
}


userUnitDS jObjectTransUserDataInput(JNIEnv *env,jobjectArray userData){
//	if(userData == 0) return 0;
	userUnitDS userDataReturn;
	jclass userDataClass = (*env)->GetObjectClass(env,userData);
	jfieldID averageMenstruationLengthID = (*env)->GetFieldID(env,userDataClass,"averageMenstruationLength","F");
  	jfieldID validCycleCountID = (*env)->GetFieldID(env,userDataClass,"validCycleCount","I");
  	jfieldID menstruationLengthErrorID = (*env)->GetFieldID(env,userDataClass,"menstruationLengthError","F");
  	jfieldID averageCycleLengthID = (*env)->GetFieldID(env,userDataClass,"averageCycleLength","F");
  	jfieldID cycleLengthErrorID = (*env)->GetFieldID(env,userDataClass,"cycleLengthError","F");
  	jfieldID averageLuteumPhaseLengthID = (*env)->GetFieldID(env,userDataClass,"averageLuteumPhaseLength","F");
  	jfieldID averageOvulationDayID = (*env)->GetFieldID(env,userDataClass,"averageOvulationDay","F");
  	jfieldID abnormalCaseAlertID = (*env)->GetFieldID(env,userDataClass,"abnormalCaseAlert","I");
  	
  	jfloat averageMenstruationLength = (jfloat)(*env)->GetFloatField(env,userData,averageMenstruationLengthID);
  	jint validCycleCount = (*env)->GetIntField(env,userData,validCycleCountID);
  	jfloat menstruationLengthError = (jfloat)(*env)->GetFloatField(env,userData,menstruationLengthErrorID);
  	jfloat averageCycleLength = (*env)->GetFloatField(env,userData,averageCycleLengthID);
  	jfloat cycleLengthError = (*env)->GetFloatField(env,userData,cycleLengthErrorID);
  	jfloat averageLuteumPhaseLength = (*env)->GetFloatField(env,userData,averageLuteumPhaseLengthID);
  	jfloat averageOvulationDay = (*env)->GetFloatField(env,userData,averageOvulationDayID);
  	
  	jint abnormalCaseAlert = (*env)->GetIntField(env,userData,abnormalCaseAlertID);
	userDataReturn.averageMenstruationLength = averageMenstruationLength; 
	userDataReturn.validCycleCount = validCycleCount; 
	userDataReturn.menstruationLengthError = menstruationLengthError; 
	userDataReturn.averageCycleLength = averageCycleLength; 
	userDataReturn.cycleLengthError = cycleLengthError ; 
	userDataReturn.averageLuteumPhaseLength = averageLuteumPhaseLength; 
	userDataReturn.averageOvulationDay = averageOvulationDay; 
	userDataReturn.abnormalCaseAlert = abnormalCaseAlert; 
	return userDataReturn;
	  
	  
	//  printf("userData  averLength:%f \n",avearageValue);
	   
  	//printf("userData  validCycle:%d \n",validCycleValue);
  	//fflush(stdout);
}

void testtransUserData(userUnitDS *userdata){
	printf("testTransUserData------/n");
	printf("validCycleCount:%d\n",userdata->validCycleCount);
	printf("averageMenstruationLength:%f\n",userdata->averageMenstruationLength);
	printf("menstruationLengthError:%f\n",userdata->menstruationLengthError);
	printf("averageCycleLength:%f\n",userdata->averageCycleLength);
	printf("cycleLengthError:%f\n",userdata->cycleLengthError);
	printf("averageLuteumPhaseLength:%f\n",userdata->averageLuteumPhaseLength);
	
	printf("averageOvulationDay:%f\n",userdata->averageOvulationDay);
	printf("abnormalCaseAlert:%d\n",userdata->abnormalCaseAlert);
}

void userUnitUpdate(JNIEnv *env,jobject userObject, userUnitDS userData){
	jclass userDataClass = (*env)->GetObjectClass(env,userObject);
	jfieldID averageMenstruationLengthID = (*env)->GetFieldID(env,userDataClass,"averageMenstruationLength","F");
  	jfieldID validCycleCountID = (*env)->GetFieldID(env,userDataClass,"validCycleCount","I");
  	jfieldID menstruationLengthErrorID = (*env)->GetFieldID(env,userDataClass,"menstruationLengthError","F");
  	jfieldID averageCycleLengthID = (*env)->GetFieldID(env,userDataClass,"averageCycleLength","F");
  	jfieldID cycleLengthErrorID = (*env)->GetFieldID(env,userDataClass,"cycleLengthError","F");
  	jfieldID averageLuteumPhaseLengthID = (*env)->GetFieldID(env,userDataClass,"averageLuteumPhaseLength","F");
  	jfieldID averageOvulationDayID = (*env)->GetFieldID(env,userDataClass,"averageOvulationDay","F");
  	jfieldID abnormalCaseAlertID = (*env)->GetFieldID(env,userDataClass,"abnormalCaseAlert","I");
  	(*env)->SetIntField(env,userObject,validCycleCountID,userData.validCycleCount);
  	(*env)->SetIntField(env,userObject,abnormalCaseAlertID,userData.abnormalCaseAlert);
  	(*env)->SetFloatField(env,userObject,averageMenstruationLengthID,userData.averageMenstruationLength);
  	(*env)->SetFloatField(env,userObject,menstruationLengthErrorID,userData.menstruationLengthError);
  	(*env)->SetFloatField(env,userObject,averageCycleLengthID,userData.averageCycleLength);
  	(*env)->SetFloatField(env,userObject,cycleLengthErrorID,userData.cycleLengthError);
  	(*env)->SetFloatField(env,userObject,averageLuteumPhaseLengthID,userData.averageLuteumPhaseLength);
  	(*env)->SetFloatField(env,userObject,averageOvulationDayID,userData.averageOvulationDay);
  	return;
}


void printCycleOutResult(JNIEnv *env,jobjectArray cycleInputArray, int cycleInputLength){
	if(cycleInputArray == 0 || cycleInputLength == 0){
		return NULL;
	}
	LOGW("log in C al now this is out put the trans result using to check !\n");
	
	jobject cycleInputx = (jobject)(*env)->GetObjectArrayElement(env,cycleInputArray,0);
	jclass cycleClass   = (*env)->GetObjectClass(env,cycleInputx);
	jfieldID cycleDataID = (*env)->GetFieldID(env,cycleClass,"cycleData","[J");
  	jfieldID cycleNumberID = (*env)->GetFieldID(env,cycleClass,"cycleNumber","I");
  	jfieldID ovulationDayUserRecordBasisID = (*env)->GetFieldID(env,cycleClass,"ovulationDayUserRecordBasis","I");
  	int x = 0;
  	for(x = 0; x < cycleInputLength; x++){
		jobject cycleInput = (jobject)(*env)->GetObjectArrayElement(env,cycleInputArray,x);

		jint cycleNumberValue  = (jint)(*env)->GetIntField(env,cycleInput,cycleNumberID);
		jint ovulationDayUserRecordBasis = (jint)(*env)->GetIntField(env,cycleInput,ovulationDayUserRecordBasisID);
		
		jlongArray cycleDataArray = (jlongArray)(*env)->GetObjectField(env,cycleInput,cycleDataID);
		LOGW("cycleNum:%d\n",cycleNumberValue);
		jsize cycleDataLength = (jsize)(*env)->GetArrayLength(env,cycleDataArray);
		
		jlong *cycleData = (*env)->GetLongArrayElements(env,cycleDataArray,0);


		int index = 0;
		for( index = 0 ; index < cycleDataLength; index++){
			#ifdef JAVA_OUTPUT
			LOGW("cycleData %d --> %d\n",index,cycleData[index]);
			#endif
		}

	}
}


/*
void cycleOutputUpdate(JNIEnv *env,jobjectArray cycleOutObjectArray, cycleUnitDS* cycleOutputC, int length){
	jobject cycleOutputx = (jobject)(*env)->GetObjectArrayElement(env,cycleOutObjectArray,0);
	jclass cycleClass   = (*env)->GetObjectClass(env,cycleOutputx);
	jfieldID cycleDataID = (*env)->GetFieldID(env,cycleClass,"cycleData","[J");
  	jfieldID cycleNumberID = (*env)->GetFieldID(env,cycleClass,"cycleNumber","I");
  	jfieldID ovulationDayUserRecordBasisID = (*env)->GetFieldID(env,cycleClass,"ovulationDayUserRecordBasis","I");
  	
	int indexCycle = 0;
	int index = 0;
	for(; indexCycle < length; indexCycle++){
		for(index = 0; index < 26; index++){
			LOGW("log in C AL in cycleOutputUpdate cycleOutC %d : %ld! \n", index,cycleOutputC[indexCycle].cycleData[index]);//fflush(stdout);
		}
	}

	
	int  x = 0;
  	for(x = 0; x < length; x++){
  		//printf("cycleOutputUpdate x: %d!/n",x);fflush(stdout);
		jobject cycleOutput = (jobject)(*env)->GetObjectArrayElement(env,cycleOutObjectArray,x);
		
		(*env)->SetIntField(env,cycleOutput,cycleNumberID,cycleOutputC[x].cycleNumber);
  		(*env)->SetIntField(env,cycleOutput,ovulationDayUserRecordBasisID,cycleOutputC[x].ovulationDayUserRecordBasis);
		jlongArray cycleDataArray = (jlongArray)(*env)->GetObjectField(env,cycleOutput,cycleDataID);
		
		(*env)->SetLongArrayRegion(env,cycleDataArray,0,26,cycleOutputC[x]->cycleData);
	}
	//测试是否向里面打印的数据是正常的
	//测试完毕后需要删除 start
	printCycleOutResult(env,cycleOutObjectArray,length);	
	//end
}
*/

void cycleOutputUpdate(JNIEnv *env,jobjectArray cycleOutObjectArray, cycleUnitDS* cycleOutputC, int length){
	jobject cycleOutputx = (jobject)(*env)->GetObjectArrayElement(env,cycleOutObjectArray,0);
	jclass cycleClass   = (*env)->GetObjectClass(env,cycleOutputx);
	jfieldID cycleDataID_0 = (*env)->GetFieldID(env,cycleClass,"menstruationStartForecast","J");
	jfieldID cycleDataID_1 = (*env)->GetFieldID(env,cycleClass,"menstruationEndForecast","J");
	jfieldID cycleDataID_2 = (*env)->GetFieldID(env,cycleClass,"menstruationStartConfirm","J");
	jfieldID cycleDataID_3 = (*env)->GetFieldID(env,cycleClass,"menstruationEndConfirm","J");
	jfieldID cycleDataID_4 = (*env)->GetFieldID(env,cycleClass,"BBTRiseDay","J");
	jfieldID cycleDataID_5 = (*env)->GetFieldID(env,cycleClass,"peakDay","J");
	jfieldID cycleDataID_6 = (*env)->GetFieldID(env,cycleClass,"ovulationDayForecast","J");
	jfieldID cycleDataID_7 = (*env)->GetFieldID(env,cycleClass,"ovulationDayConfirm","J");
	jfieldID cycleDataID_8 = (*env)->GetFieldID(env,cycleClass,"ovulationDayUserRecord","J");
	jfieldID cycleDataID_9 = (*env)->GetFieldID(env,cycleClass,"ovulationDayBBTRise","J");
	jfieldID cycleDataID_10 = (*env)->GetFieldID(env,cycleClass,"ovulationDayNextMenstruation","J");
	jfieldID cycleDataID_11 = (*env)->GetFieldID(env,cycleClass,"fertileWindowStartForecast","J");
	jfieldID cycleDataID_12 = (*env)->GetFieldID(env,cycleClass,"fertileWindowEndForecast","J");
	jfieldID cycleDataID_13 = (*env)->GetFieldID(env,cycleClass,"fertileWindowStartConfirm","J");
	jfieldID cycleDataID_14 = (*env)->GetFieldID(env,cycleClass,"fertileWindowEndConfirm","J");
	jfieldID cycleDataID_15 = (*env)->GetFieldID(env,cycleClass,"dangerWindowStartForecast","J");
	jfieldID cycleDataID_16 = (*env)->GetFieldID(env,cycleClass,"dangerWindowEndForecast","J");
	jfieldID cycleDataID_17 = (*env)->GetFieldID(env,cycleClass,"dangerWindowStartConfirm","J");
	jfieldID cycleDataID_18 = (*env)->GetFieldID(env,cycleClass,"dangerWindowEndConfirm","J");
	jfieldID cycleDataID_19 = (*env)->GetFieldID(env,cycleClass,"nextMenstruationStartForecast","J");
	jfieldID cycleDataID_20 = (*env)->GetFieldID(env,cycleClass,"nextMenstruationEndForecast","J");
	jfieldID cycleDataID_21 = (*env)->GetFieldID(env,cycleClass,"nextOvulationDayForecast","J");
	jfieldID cycleDataID_22 = (*env)->GetFieldID(env,cycleClass,"nextFertileWindowStartForecast","J");
	jfieldID cycleDataID_23 = (*env)->GetFieldID(env,cycleClass,"nextFertileWindowEndForecast","J");
	jfieldID cycleDataID_24 = (*env)->GetFieldID(env,cycleClass,"nextDangerWindowStartForecast","J");
	jfieldID cycleDataID_25 = (*env)->GetFieldID(env,cycleClass,"nextDangerWindowEndForecast","J");
	
  	jfieldID cycleNumberID = (*env)->GetFieldID(env,cycleClass,"cycleNumber","I");
  	jfieldID ovulationDayUserRecordBasisID = (*env)->GetFieldID(env,cycleClass,"ovulationDayUserRecordBasis","I");
  	
	int indexCycle = 0;
	int index = 0;
	for(; indexCycle < length; indexCycle++){
		for(index = 0; index < 26; index++){
			LOGW("log in C AL in cycleOutputUpdate cycleOutC %d : %ld! \n", index,cycleOutputC[indexCycle].cycleData[index]);//fflush(stdout);
		}
	}

	
	int x = 0;
  	for(x = 0; x < CYCLE_OUTPUT_LEN; x++){
  		//printf("cycleOutputUpdate x: %d!/n",x);fflush(stdout);
		jobject cycleOutput = (jobject)(*env)->GetObjectArrayElement(env,cycleOutObjectArray,x);
		if(x < length){
			(*env)->SetIntField(env,cycleOutput,cycleNumberID,cycleOutputC[x].cycleNumber);
			(*env)->SetIntField(env,cycleOutput,ovulationDayUserRecordBasisID,cycleOutputC[x].ovulationDayUserRecordBasis);
			//jlongArray cycleDataArray = (jlongArray)(*env)->GetObjectField(env,cycleOutput,cycleDataID);
			
			//(*env)->SetLongArrayRegion(env,cycleDataArray,0,26,cycleOutputC[x]->cycleData);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_0,cycleOutputC[x].cycleData[0]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_1,cycleOutputC[x].cycleData[1]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_2,cycleOutputC[x].cycleData[2]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_3,cycleOutputC[x].cycleData[3]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_4,cycleOutputC[x].cycleData[4]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_5,cycleOutputC[x].cycleData[5]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_6,cycleOutputC[x].cycleData[6]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_7,cycleOutputC[x].cycleData[7]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_8,cycleOutputC[x].cycleData[8]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_9,cycleOutputC[x].cycleData[9]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_10,cycleOutputC[x].cycleData[10]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_11,cycleOutputC[x].cycleData[11]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_12,cycleOutputC[x].cycleData[12]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_13,cycleOutputC[x].cycleData[13]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_14,cycleOutputC[x].cycleData[14]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_15,cycleOutputC[x].cycleData[15]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_16,cycleOutputC[x].cycleData[16]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_17,cycleOutputC[x].cycleData[17]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_18,cycleOutputC[x].cycleData[18]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_19,cycleOutputC[x].cycleData[19]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_20,cycleOutputC[x].cycleData[20]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_21,cycleOutputC[x].cycleData[21]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_22,cycleOutputC[x].cycleData[22]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_23,cycleOutputC[x].cycleData[23]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_24,cycleOutputC[x].cycleData[24]);
			(*env)->SetLongField(env,cycleOutput,cycleDataID_25,cycleOutputC[x].cycleData[25]);
			
		}else{
			(*env)->SetIntField(env,cycleOutput,cycleNumberID,-10);
			
		}
		
		
	}
	

}



void dayOutUpdate(JNIEnv *env,jobjectArray dayOutObjectArray, dayUnitDSOutput* dayOutputC,int dayOutputLength){
//	jobject dayOutputx = (jobject)(*env)->GetObjectArrayElement(env,dayOutObjectArray,0);
//	jclass dayOutputclass =  (*env)->GetObjectClass(env,dayOutputx);
//
//	jfieldID dayOutCycleID = (*env)->GetFieldID(env,dayOutputclass,"dayOfCycle","I");
//	jfieldID dateoutID       = (*env)->GetFieldID(env,dayOutputclass,"date","J");
//
//	jfieldID periodAchieveForecastID = (*env)->GetFieldID(env,dayOutputclass,"periodAchieveForecast","I");
//	jfieldID periodAchieveConfirmID = (*env)->GetFieldID(env,dayOutputclass,"periodAchieveConfirm","I");
//	jfieldID periodAvoidForecastID = (*env)->GetFieldID(env,dayOutputclass,"periodAvoidForecast","I");
//	jfieldID periodAvoidConfirmID = (*env)->GetFieldID(env,dayOutputclass,"periodAvoidConfirm","I");
//	jfieldID homePageMenstruationEndID = (*env)->GetFieldID(env,dayOutputclass,"homePageMenstruationEnd","I");
//	jfieldID homePageOvulationID = (*env)->GetFieldID(env,dayOutputclass,"homePageOvulation","I");
//	jfieldID homePageNextMenstruationID = (*env)->GetFieldID(env,dayOutputclass,"homePageNextMenstruation","I");
//	jfieldID dayOfCycleID = (*env)->GetFieldID(env,dayOutputclass,"dayOfCycle","I");
//	jfieldID homePageConceptionChanceID = (*env)->GetFieldID(env,dayOutputclass,"homePageConceptionChance","F");
	
	int x= 0;
	
	for(x = 0; x < dayOutputLength-1; x++){

		LOGW("dayOutUpdate x: %d!/n",x);fflush(stdout);

//		jobject dayOutput = (jobject)(*env)->GetObjectArrayElement(env,dayOutObjectArray,x);
//		(*env)->SetIntField(env,dayOutput,dayOutCycleID,dayOutputC[x].dayOfCycle);
//		(*env)->SetLongField(env,dayOutput,dateoutID,dayOutputC[x].date);
//		(*env)->SetIntField(env,dayOutput,periodAchieveForecastID,dayOutputC[x].periodAchieveForecast);
//		(*env)->SetIntField(env,dayOutput,periodAchieveConfirmID,dayOutputC[x].periodAchieveConfirm);
//		(*env)->SetIntField(env,dayOutput,periodAvoidForecastID,dayOutputC[x].periodAvoidForecast);
//		(*env)->SetIntField(env,dayOutput,periodAvoidConfirmID,dayOutputC[x].periodAvoidConfirm);
//		(*env)->SetIntField(env,dayOutput,homePageMenstruationEndID,dayOutputC[x].homePageMenstruationEnd);
//		(*env)->SetIntField(env,dayOutput,homePageOvulationID,dayOutputC[x].homePageOvulation);
//		(*env)->SetIntField(env,dayOutput,homePageNextMenstruationID,dayOutputC[x].homePageNextMenstruation);
//		(*env)->SetIntField(env,dayOutput,dayOfCycleID,dayOutputC[x].dayOfCycle);
//		(*env)->SetFloatField(env,dayOutput,homePageConceptionChanceID,dayOutputC[x].homePageConceptionChance);
	}
	return ;
}

#endif
